import Vue from 'vue';
import App from './App';
import '@/utils/index.js';
import {defaultLanguage, domain} from '@/config.js';
import {setStore, getStore} from '@/utils/storage.js';
import VueI18n from 'vue-i18n';
import enLang from './static/language/en-us.js';
import cnLang from './static/language/zh-cn.js';
import uView from "uview-ui";
Vue.use(uView);

Vue.use(VueI18n);

Vue.config.productionTip = false

App.mpType = 'app'

// vuex
import store from './store'  
Vue.prototype.$store = store  

//多语言
const LANGUAGE_ARR = ['zh-cn', 'en-us']
const currentLang = uni.getStorageSync('lang') || defaultLanguage
if(LANGUAGE_ARR.indexOf(currentLang) === -1){
	uni.setStorageSync('lang', defaultLanguage)
}
const i18n = new VueI18n({
	locale: currentLang,
	messages: {
		'zh-cn': cnLang,
		'en-us': enLang
	}
})
Vue.prototype._i18n = i18n

const app = new Vue({
    ...App,
	store,
	i18n
})
app.$mount()

//全局toast
function toast(title){
	// #ifdef APP-PLUS
	plus.nativeUI.toast(title)
	// #endif
	// #ifdef H5
	uni.showToast({
		title: title,
		duration: 1000,
		icon:'none'
	})
	// #endif
}
Vue.prototype.$toast=toast;

//网络请求
import http from './utils/http'
http.config.baseUrl = domain
Vue.prototype.$get = http.get;
Vue.prototype.$post = http.post;

//缓存
Vue.prototype.$setStore = setStore;
Vue.prototype.$getStore = getStore;


//底部导航栏
function setTabBarLang () {
	uni.setTabBarItem({
		index: 0,
		text: this.$t('tabBar.tit1')
	});
	uni.setTabBarItem({
		index: 1,
		text: this.$t('tabBar.tit2')
	});
	uni.setTabBarItem({
		index: 2,
		text: this.$t('tabBar.tit3')
	});
	uni.setTabBarItem({
		index: 3,
		text: this.$t('tabBar.tit4')
	});
}
Vue.prototype.$setTabBarLang = setTabBarLang
